package top.infopub.mgr.flow.service.impl;


import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import top.infopub.generic.GenericDao;
import top.infopub.generic.GenericServiceImpl;
import top.infopub.mgr.flow.cnst.FlowTemplateEnum;
import top.infopub.mgr.flow.dao.TestBizDao;
import top.infopub.mgr.flow.domain.TestBizDomain;
import top.infopub.mgr.flow.service.TestBizService;
import top.infopub.mgr.flow.service.WsFlowProcessService;
import top.infopub.model.flow.TestBiz;
import top.infopub.security.util.SessionUserUtils;
import top.infopub.util.IdFactory;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;


@Service
public class TestBizServiceImpl extends GenericServiceImpl<TestBiz, String> implements TestBizService {

    @Autowired
    private TestBizDao testBizDao;

    @Autowired
    private WsFlowProcessService wsFlowProcess;

    @Override
    public GenericDao<TestBiz, String> getDao() {
        return testBizDao;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void insertAndFlowProcess(TestBiz model) {
        String srcBizSguid = IdFactory.getUUIDUpper();
        String processId = IdFactory.getUUIDUpper();
        model.setId(srcBizSguid);
        model.setProcessStatus("1");
        model.setProcessId(processId);
        model.setAddBy(SessionUserUtils.getSessionUserId());
        model.setAddTime(new Date());
        // 新增业务数据
        this.insert(model);

        // TODO 注意 这里根据不同的业务分支判断条件 获得不同enum
        FlowTemplateEnum templateEnum = FlowTemplateEnum.FLOW_TEST_BIZ;
        // 处理工作流数据
        wsFlowProcess.launch(templateEnum, srcBizSguid, processId, null);
    }

    @Override
    public Page<TestBizDomain> queryPageMySee(Page<TestBizDomain> page, TestBiz paramVo) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        return (Page<TestBizDomain>)testBizDao.selectMySeeByEntityWhere(paramVo);
    }

}